home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2614.ZIP / TBROWS.ZIP / TTBR2.PRG < prev    next >
Text File  |  1990-10-22  |  4KB  |  166 lines

  1. /*****
  2.  *
  3.  * TTBR2.PRG
  4.  * Second example for TBROWSE class using a database file
  5.  *
  6.  * 19 October 90
  7.  * Luiz Quintela - Nantucket Corp
  8.  *
  9.  * Clipper ttbr2 /N/W/A/B
  10.  * RTLINK FILE ttbr2 PLL base50
  11.  *
  12.  */
  13.  
  14. // Include Header Files
  15. // This will make handling keystrokes 
  16. // a bit easier!
  17. #include "inkey.ch"
  18.  
  19. FUNCTION Main()
  20. // Your variables
  21. LOCAL b, column, nKey
  22. SET SCOREBOARD OFF
  23. SET DATE       BRITISH
  24. SET CONFIRM    ON
  25.  
  26. // First open your file, with indexes, etc.
  27. USE test INDEX test NEW            // Use NEW in lieu of SELECT 0
  28.  
  29. // Prepare a beautiful color screen
  30. // I do not like to put several commands in a single line
  31. // but this is just to show what you can do with Clipper
  32. SETCOLOR( "BG/B,GR+/B,,,BG/N" ); CLS
  33.  
  34. // Ok! Now is time to create a TBrowseDB object
  35. // TBrowseDB( top, left, bottom, right ) ===> Object
  36.  
  37. b := TBrowseDB( 2, 2, 20, 48)
  38.  
  39. // This time, we will use and separators between columns and
  40. // header
  41.  
  42. b:colSep := " │ "
  43.  
  44. // colSep contains an optional character used to draw a 
  45. // vertical separator if there is another column to the
  46. // left of it.
  47.  
  48. b:headSep := "═╤═"
  49.  
  50. // headSep contains an optional character string used
  51. // to draw a horizontal separator between the heading and
  52. // data values
  53.  
  54. // Note that TBrowseDB() creates an object with no column
  55. // objects. In order to make the object usable, a column must be
  56. // added for each field to display.
  57. // In this example we will use five fields.
  58. // TBColumnNew( cHeading, bBlock ) =====> Object
  59.  
  60. column := TBColumnNew( "Field 1", {|| test->fld1} )
  61.  
  62. // Returns a new column object with specified heading and data
  63. // retrieval block
  64.  
  65. b:addColumn( column )
  66.  
  67. // addColumn( objColumn ) =====> self
  68. // Adds a new column object to the browse object and 
  69. // TBrowse:colCount is increased by one.
  70. // Repeat the same to other fields
  71.  
  72. column := TBColumnNew( "Field 2", {|| test->fld2} )
  73. b:addColumn( column )
  74. column := TBColumnNew( "Field 3", {|| test->fld3} )
  75. b:addColumn( column )
  76. column := TBColumnNew( "Field 4", {|| test->fld4} )
  77. b:addColumn( column )
  78. column := TBColumnNew( "Field 5", {|| test->fld5} )
  79. b:addColumn( column )
  80.  
  81.  
  82. // It is time to put this programme to work
  83. WHILE .T.
  84.    // Ok! It is time to stabilize display
  85.    // stabilize() =====> self
  86.    // Performs incremental stabilization. Stabilization is 
  87.     // performed in increments so that it can be interrupted 
  88.     // by any asynchronous event.
  89.    // A value of .T. is returned indicating the object is stable
  90.  
  91.    WHILE ( !b:stabilize() )
  92.       nKey := InKey()
  93.       IF ( nKey != 0 )
  94.          EXIT // abort if a key is waiting
  95.  
  96.       ENDIF
  97.  
  98.    END
  99.  
  100.    // b:stable contains .T. if the browse object is stable
  101.  
  102.    // Display is stable
  103.    IF ( b:stable )
  104.       // everything's done; just wait for a key
  105.       nKey := INKEY(0)
  106.  
  107.    ENDIF
  108.  
  109.    // Up to this point nothing changed. But we need to include
  110.    // a keystroke handler. It will use cursor movement methods
  111.  
  112.    // Process key
  113.     IF ( nKey == K_DOWN )
  114.       b:down()
  115.  
  116.    ELSEIF ( nKey == K_UP )
  117.       b:up()
  118.  
  119.    ELSEIF ( nKey == K_PGDN )
  120.       b:pageDown()
  121.  
  122.    ELSEIF ( nKey == K_PGUP )
  123.       b:pageUp()
  124.  
  125.    ELSEIF ( nKey == K_CTRL_PGUP )
  126.       b:goTop()
  127.  
  128.    ELSEIF ( nKey == K_CTRL_PGDN )
  129.       b:goBottom()
  130.  
  131.    ELSEIF ( nKey == K_RIGHT )
  132.       b:right()
  133.  
  134.    ELSEIF ( nKey == K_LEFT )
  135.       b:left()
  136.  
  137.    ELSEIF ( nKey == K_HOME )
  138.       b:home()
  139.  
  140.    ELSEIF ( nKey == K_END )
  141.       b:end()
  142.  
  143.    ELSEIF ( nKey == K_CTRL_LEFT )
  144.       b:panLeft()
  145.  
  146.    ELSEIF ( nKey == K_CTRL_RIGHT )
  147.       b:panRight()
  148.  
  149.    ELSEIF ( nKey == K_CTRL_HOME )
  150.       b:panHome()
  151.  
  152.    ELSEIF ( nKey == K_CTRL_END )
  153.       b:panEnd()
  154.  
  155.    ELSEIF ( nKey == K_ESC )
  156.         CLS; QUIT
  157.  
  158.     ENDIF
  159.  
  160.    // About cursor movement methods I strongly recommend you 
  161.    // read the manual or the Guides
  162.  
  163. END
  164.  
  165. /* EOF - TTBR2.PRG */
  166.